/*
 * @Autor: dingxiaolin
 * @Date: 2021-07-20 22:39:14
 * @LastEditors: dingxiaolin
 * @LastEditTime: 2021-07-20 22:39:15
 */
import { onMounted, onUnmounted, ref } from "vue";

function useWindowResize() {
    const width = ref(0);
    const height = ref(0);

    function onResize() {
        width.value = window.innerWidth;
        height.value = window.innerHeight;
    }

    onMounted(() => {
        window.addEventListener("resize", onResize);
        onResize();
    });

    onUnmounted(() => {
        window.removeEventListener("resize", onResize);
    });

    return {
        width,
        height
    };
}

export default useWindowResize;